﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;
//using IndyMosaic.Models.Blog;
using IndyMosaic.Core.Extensions;

namespace IndyMosaic.Core.Notifications.Blog
{
    //public class CommentNotifier : SimpleNotifier
    //{
        //public Entry AssociatedBlogEntry { get; set; }
        //public Comment NewComment
        //{
        //    get
        //    {
        //        return (Comment)Trigger;
        //    }
        //    set 
        //    {
        //        Trigger = value;
        //    }
        //}

        //public CommentNotifier(Comment comment): base(comment)
        //{
        //    AssociatedBlogEntry = comment.Entry;
        //}

        //#region Support for SimpleNotifier
        //protected override IEnumerable<Subscriber> GetSubscribers()
        //{
        //    IEnumerable<Subscriber> subscribers = null;
        //    switch (NewComment.ApprovalStatus)
        //    {
        //        case ApprovalStatus.Pending:
        //            subscribers = GetSubscribersForPendingComment();
        //            break;
        //        case ApprovalStatus.Approved:
        //            subscribers = GetSubscribersForApprovedComment();
        //            break;
        //        case ApprovalStatus.Rejected:
        //            subscribers = GetSubscribersForRejectedComment();
        //            break;
        //        default:
        //            subscribers = new List<Subscriber>();
        //            break;
        //    }

        //    return subscribers;
        //}

        //private IEnumerable<Subscriber> GetSubscribersForPendingComment()
        //{
        //    List<Subscriber> subscribers = new List<Subscriber>();
        //    subscribers.Add(GetBlogEntryAuthor());
        //    return subscribers;
        //}

        //private IEnumerable<Subscriber> GetSubscribersForApprovedComment()
        //{
        //    var subscr = from c in AssociatedBlogEntry.Comments
        //                 where !string.IsNullOrEmpty(c.EmailAddress)
        //                 && c.EmailAddress != NewComment.EmailAddress
        //                 && c.Subscribe
        //                 select new Subscriber() { Address = c.EmailAddress, Name = c.AuthorName };

        //    if (NewComment.ApprovedByUserID != AssociatedBlogEntry.UserID)
        //    {
        //        Subscriber entryAuthor = GetBlogEntryAuthor();
        //        List<Subscriber> authorsList = new List<Subscriber>();
        //        authorsList.Add(entryAuthor);
        //        subscr.Concat(authorsList);
        //    }

        //    return subscr.Distinct(new SubscriberAddressComparer()).ToList();
        //}

        //private IEnumerable<Subscriber> GetSubscribersForRejectedComment()
        //{
        //    List<Subscriber> subscribers = new List<Subscriber>();
        //    if(!string.IsNullOrEmpty(NewComment.EmailAddress))
        //    {
        //        subscribers.Add(new Subscriber() { Address = NewComment.EmailAddress, Name = NewComment.AuthorName });
        //    }
        //    return subscribers;
        //}

        //private Subscriber GetBlogEntryAuthor()
        //{
        //    string authorEmailAddress =
        //        System.Web.Security.Membership.GetUser(AssociatedBlogEntry.UserID).Email;

        //    Subscriber entryAuthor = new Subscriber() { Name = AssociatedBlogEntry.AuthorName, Address = authorEmailAddress };
        //    return entryAuthor;
        //}

        //protected override void SendNotification()
        //{
        //    switch (NewComment.ApprovalStatus)
        //    {
        //        case ApprovalStatus.Pending:
        //            Message = GetMessageForPendingComment();
        //            break;
        //        case ApprovalStatus.Approved:
        //            Message = GetMessageForApprovedgComment();
        //            break;
        //        case ApprovalStatus.Rejected:
        //            Message = GetMessageForRejectedComment();
        //            break;
        //        default:
        //            break;
        //    }

        //    Email.EmailUtility.SendEmail(Email.EmailUtility.NotificationsAddress, 
        //        Subscribers.GetMailAddressCollection(), 
        //        string.Format("A new comment on {0}", AssociatedBlogEntry.Title), Message);
        //}

        //private string GetMessageForPendingComment()
        //{
        //    return string.Format("A comment was added to the indymosaic.org blog entery titled: {0} <br /> <p>{1}</p><p>Please loging to approve or reject the comment.</p",
        //        AssociatedBlogEntry.Title, NewComment.Content);
        //}
        //private string GetMessageForApprovedgComment()
        //{
        //    return string.Format("A comment was added to the indymosaic.org blog entery titled: {0} <br /> <p>{1}</p>",
        //        AssociatedBlogEntry.Title, NewComment.Content);
        //}
        //private string GetMessageForRejectedComment()
        //{
        //    return string.Format("Sorry your comment was not approved on the indymosaic.org blog entery titled: {0} <br /> <p>{1}</p>",
        //        AssociatedBlogEntry.Title, NewComment.Content);
        //}
        //#endregion
//    }
}
